package com.hhf.rpc.core.server.impl;

import com.hhf.rpc.core.handler.HttpServerHandler;
import com.hhf.rpc.core.server.HttpServer;
import io.vertx.core.Vertx;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author hhf
 * @Date 2024/10/15
 * @Description
 */
@Slf4j
public class VertxHttpServer implements HttpServer {

    @Override
    public void doStart(int port) {
        Vertx vertx = Vertx.vertx();
        io.vertx.core.http.HttpServer server = vertx.createHttpServer();

        //添加自定义请求处理器
        server.requestHandler(new HttpServerHandler());

        server.listen(port,result -> {
            if (result.succeeded()){
                log.info("vertx服务器启动成功,正在监听端口:{}",port);
            }else {
                log.error("vertx服务器启动失败,报错信息:{}",result.cause());
            }
        });
    }
}
